/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package monopoli.gui;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import monopoli.Monopoli;

/**
 *
 * @author Claudio
 */
public class MyCellRenderer extends JLabel implements ListCellRenderer {
     

     // This is the only method defined by ListCellRenderer.
     // We just reconfigure the JLabel each time we're called.

     public Component getListCellRendererComponent(
       JList list,
       Object value,            // value to display
       int index,               // cell index
       boolean isSelected,      // is the cell selected
       boolean cellHasFocus)    // the list and the cell have the focus
     {
         if(value != null) {
         String path = new String();
         //System.out.println("SIII!");
         String s = value.toString();
         setText(s);
         //setIcon((s.length() > 10) ? longIcon : shortIcon);
         int pedina = Monopoli.getMonopoliPartita().ricavaPedina(s);
         if(pedina == 6)
            path = "../resources/" + "fiascoSmall" + ".png";
         else if (pedina == 1)
            path = "../resources/" + "funghettoSmall" + ".png";
         else if (pedina == 5)
            path = "../resources/" + "melaSmall" + ".png";
         else if (pedina == 3)
            path = "../resources/" + "piantinaSmall" + ".png";
        else if (pedina == 2)
            path = "../resources/" + "candelaSmall" + ".png";
        else if (pedina ==4)
             path = "../resources/" + "peraSmall" + ".png";
        else {
            path = "";
            setText(" + " + s);
        }

         java.net.URL imgURL = getClass().getResource(path);
              if (imgURL == null) {
                System.out.println("PATH IMMAGINE NON TROVATO!");
            } else {
                //System.out.println(path);
                setIcon(new ImageIcon(imgURL));
            }

        
   	   if (isSelected) {
             setBackground(list.getSelectionBackground());
	       setForeground(list.getSelectionForeground());
	   }
         else {
	       setBackground(list.getBackground());
	       setForeground(list.getForeground());
	   }
	   setEnabled(list.isEnabled());
	   setFont(list.getFont());
         setOpaque(true);
         return this;
         }
         return this;
     }
 }
